import 'dart:math';

import 'package:flutter/material.dart';

void main(List<String> args) {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  var count = 0;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      body: Center(
          child: AnimatedSwitcher(
        transitionBuilder: (Widget child, Animation<double> animation) {
          //执行缩放动画
          return ScaleTransition(scale: animation, child: child);
        },
        duration: const Duration(milliseconds: 500),
        child: Text(
          '$count',
          key: UniqueKey(),
          style: const TextStyle(
              fontSize: 100, fontWeight: FontWeight.bold, color: Colors.blue),
        ),
      )),
      floatingActionButton: ElevatedButton(
        onPressed: () {
          setState(() {
            count++;
          });
        },
        child: const Text('执行动画'),
      ),
    ));
  }
}

class Box extends StatefulWidget {
  const Box({super.key});

  @override
  State<Box> createState() => _BoxState();
}

class _BoxState extends State<Box> {
  var color = Color.fromRGBO(
      Random().nextInt(255), Random().nextInt(255), Random().nextInt(255), 1);
  changeColor() {
    setState(() {
      color = Color.fromRGBO(Random().nextInt(255), Random().nextInt(255),
          Random().nextInt(255), 1);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
        child: Container(
      width: 100,
      height: 100,
      color: color,
    ));
  }
}
